﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Imagiality.MeshProcessing
{
    public class PathBasedByIDQuery<T> : SceneQuery<T> where T:SceneObject
    {
        private Queue<uint> path;
        private ISet<uint> targetIDSet;

        public PathBasedByIDQuery(Queue<uint> path, ISet<uint> targetIDSet) : base()
        {
            this.path = path;
            this.targetIDSet = targetIDSet;
        }

        protected override bool IsMatch(SceneObject obj)
        {
            if (path.Count > 0)
                return false;

            if(targetIDSet.Contains(obj.GetID()))
            {
                targetIDSet.Remove(obj.GetID());
                return true;
            }

            return false;
        }

        protected override bool ProcessNextLevel(int level, SceneObject parent)
        {
            if (path.Count > 0)
            {
                uint first = path.ElementAt(0);
                if (parent.GetID().Equals(first))
                {
                    path.Dequeue();
                    return true;
                }
            }

            return false;
        }
    }
}
